<template>
  <el-form style="width: 60%" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

    <el-form-item label="测试项目标识" prop="case_item_id">
      <el-input v-model="ruleForm.case_item_id"></el-input>
    </el-form-item>

    <el-form-item prop="case_item_sort_id"
                  label="测试项目分类标识">
      <el-input v-model="ruleForm.case_item_sort_id"></el-input>
    </el-form-item>
    <el-form-item  prop="case_design_id"
                   label="测试用例标识">
      <el-input v-model="ruleForm.case_design_id"></el-input>
    </el-form-item>

    <el-form-item prop="case_track"
                  label="测试追踪">
      <el-input v-model="ruleForm.case_track"></el-input>
    </el-form-item>
    <el-form-item prop="case_feature"
                  label="测试子特性">
      <el-input v-model="ruleForm.case_feature"></el-input>
    </el-form-item>
    <el-form-item  prop="case_method"
                   label="测试方法">
      <el-input v-model="ruleForm.case_method"></el-input>
    </el-form-item>
    <el-form-item  prop="case_show"
                   label="测试说明">
      <el-input v-model="ruleForm.case_show"></el-input>
    </el-form-item>
    <el-form-item   prop="premise"
                    label="前提与约束">
      <el-input v-model="ruleForm.premise"></el-input>
    </el-form-item>
    <el-form-item    prop="end_condition"
                     label="终止条件">
      <el-input v-model="ruleForm.end_condition"></el-input>
    </el-form-item>
    <el-form-item    prop="case_input"
                     label="输入及操作说明">
      <el-input v-model="ruleForm.case_input"></el-input>
    </el-form-item>
    <el-form-item   prop="case_result"
                    label="期望测试结果">
      <el-input v-model="ruleForm.case_result"></el-input>
    </el-form-item>
    <el-form-item   prop="rubrics"
                    label="评估准则">
      <el-input v-model="ruleForm.rubrics"></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="密码" @click="submitForm('ruleForm')">提交</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>

  </el-form>
</template>

<script>
import axios from 'axios'

export default {
  data() {
    return {
      ruleForm: {
        case_item_id: '',
        case_item_sort_id: '',
        case_design_id: '',
        case_track: '',
        case_method: '',
        case_feature: '',
        case_show: '',
        premise: '',
        end_condition: '',
        case_input: '',
        rubrics: '',
        case_result: ''
      },
      rules: {
        case_item_id: [
          { required: true, message: '测试项目标识不能为空', trigger: 'blur' }
        ],
        case_item_sort_id: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        case_design_id: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        case_track: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      const _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios.post('http://localhost:8088/case_design/save', this.ruleForm).then(function(resp) {
            if (resp.data === 'success') {
              _this.$alert('《' + _this.ruleForm.case_design_id + '》更新成功！', '消息', {
                confirmButtonText: '确定',
                callback: action => {
                  _this.$router.push('/Main')
                }
              })
            }
          })
        } else {
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  created() {
    const _this = this
    axios.get('http://localhost:8088/case_design/findById/' + this.$route.query.id).then(function(resp) {
      _this.ruleForm = resp.data
    })
  }
}
</script>

<style scoped>

</style>
